package 笔试真题;

import java.util.Arrays;
import java.util.Scanner;

public class Huawei202198_2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] father = new int[n];
        Arrays.fill(father,-1);
        int[] values = new int[n];
        boolean[] ye = new boolean[n]; //是不是非叶子结点
        boolean[] visited = new boolean[n]; //是不是非叶子结点
        int sum = 0;
        int temp =0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            values[i] = scanner.nextInt();
            sum += values[i];
        }
        for (int i = 0; i < n - 1; i++) {
            int p = scanner.nextInt();
            ye[p] = true;
            father[scanner.nextInt()] = p;
        }
        for (int i = 0; i < ye.length; i++) {
            int tt = i;
            if(!ye[i]){
                int t1 = values[i];
                while (father[i]!=-1){
                    values[father[i]] += t1;
                    visited[i] = true;
                    i = father[i];
                    if(!visited[i]){
                        temp += values[i];
                    }
                }
            }
            i = tt;
        }
        for (int i = 0; i < n; i++) {
            int abs = Math.abs(sum - 2 * values[i]);
            if(abs>temp){
                temp = abs;
                ans = i;
            }
        }
        System.out.println(ans);
    }
}
